var modulePurviewTree;

function showmodulePurviewTree(id, tlt) {
	if (!Ext.get('modulePurviewTreeWin')) {
		// tabs for the center
		// Panel for the west
		var nav1 = new Ext.Panel({
			title : '访问权限列表',
			region : 'center',
			split : true,
			collapsible : false,
			margins : '3 3 3 0',
			frame : false,
			items : [{
				border : true,
				autoScroll : true,
				html : '<div id="modulepurviewlist" style="overflow:auto;height:400px;border:0px #000 solid;"></div>'
			}]
		});

		// Panel for the west
		var nav = new Ext.Panel({
			title : '模块&nbsp;{' + tlt + '}',
			region : 'west',
			split : true,
			width : 200,
			collapsible : false,
			margins : '3 0 3 3',
			items : [{
				border : false,
				html : '<div id="modulePurviewTree-div" style="overflow:auto;width:198px;height:400px;border:0px #000 solid;"></div>'
			}]
		});

		var win = new Ext.Window({
					id : 'modulePurviewTreeWin',
					title : "模块菜单权限设置",
					closable : true,
					resizable : false,
					// maximizable : true,
					width : 800,
					height : 465,
					border : false,
					plain : true,
					layout : 'border',
					modal : true,
					items : [nav, nav1]
				});

		win.show(this);

		initmodulePurviewTree(id, tlt);
	} else if (Ext.get('modulePurviewTreeWin').hidden()) {
		Ext.get('modulePurviewTreeWin').show();
	}
}

function initmodulePurviewTree(id, rootName) {
	var root = new Ext.tree.AsyncTreeNode({
				text : rootName,
				draggable : false,
				id : 'module_' + id
			});

	modulePurviewTree = new Ext.tree.TreePanel({
				layout : 'fit',
				renderTo : 'modulePurviewTree-div',
				useArrows : false,
				autoScroll : false,
				animate : false,
				enableDD : false,
				containerScroll : true,
				expandable : true,
				rootVisible : false,
				singleExpand : false,
				animate : true,
				border : false,
				frame : false,
				root : {
					nodeType : 'async'
				},
				// auto create TreeLoader
				dataUrl : context + '/system/module.do?method=moduletree&id='
						+ id,
				listeners : {
					'click' : function(node) {
						if (node.attributes.isroot != true) {
							var tp = node.attributes.type;
							var oid = node.attributes.realid;

							purviewlist(oid, node.text, tp, 'ISYS_MODULE_MENU','modulepurviewlist', 'purview-visit');
						} else {
							var tp = 'module';
							var oid = id;

							purviewlist(oid, node.text, tp, 'ISYS_MODULE','modulepurviewlist', 'purview-visit');
						}

					}
				}
			});

	modulePurviewTree.render();

	modulePurviewTree.expandAll();
};